package com.zhj.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhj.entity.DeviceStat;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface DeviceStatMapper extends BaseMapper<DeviceStat> {

    /**
     * 创建超级表
     */
    @Update("create stable if not exists device_stat(time timestamp, deviceName VARCHAR(32), position VARCHAR(32), speed INT) tags (deviceId VARCHAR(32))")
    int createSuperTable();

    @Insert("insert into ${tbName} using device_stat tags (#{device.deviceId}) values(#{device.time}, #{device" +
            ".deviceName}, #{device.position}, " +
            "#{device.speed})")
    int insertOne(@Param("tbName") String tbName, @Param("device") DeviceStat deviceStat);

    /**
     * 通过xml进行查询
     */
    List<DeviceStat> selectListForXml(@Param("tableName") String tableName);
}
